<template>
	<view>
		<view v-if='logs && logs.length > 0'>
			<view v-for='item in logs'>
				<view>
					<u-row>
						<u-col span='9'>
							<view style='color:#909399;margin:5px 10px;'>
								<view>
									{{item.comment}}
								</view>
								<view style='font-size:14px'>
									{{$u.timeFormat(new Date(item.createdTime), 'yyyy年mm月dd日')}}
								</view>
							</view>
						</u-col>
						<u-col span='3'>
							<view style='text-align: right;font-size: 21px;color:#606266;padding-right:5px'>
								{{item.amount}}
							</view>
						</u-col>
					</u-row>
					<u-line></u-line>
				</view>
			</view>
			<u-loadmore :status="status" />
		</view>
		<view v-else style='margin-top: 30vh'>
			<u-empty mode="list" text='暂无记录'>
			</u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				logs: [],
				status: 'loadmore',
				page: 1,
				limit: 40
			}
		},
		onReachBottom() {
			if (this.status == 'loadmore') {
				this.page++
				this.getBalanceLog()
			}
		},
		onShow() {
			this.page = 1
			this.logs = []
			this.status = 'loadmore'
			this.getBalanceLog()
		},
		methods: {
			getBalanceLog() {
				this.request.get(`api/balance-logs`, {
					'@filter': `entity.getType() == 'point'`,
					'@order': `entity.createdTime | DESC`,
					limit: this.limit,
					page: this.page
				}).then((res) => {
					if (res.data.length < this.limit) {
						this.status = 'nomore'
					}
					for (let i of res.data) {
						this.logs.push(i)
					}
				})
			}
		}
	}
</script>

<style>

</style>